<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;

 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>预览户外广告设置证</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<style type="text/css">
			.titleCss{
				font-size:100%;
				text-align:center;
				font-weight: bold;
			}
			.justifyCss{
				width:20%;
				text-align:justify;
				text-justify:distribute-all-lines;
				text-align-last:justify;
			}
			.tdCss{
				font-size:100%;
				font-weight: bold;
			}
			.inputNoborder {
			    FONT-SIZE: 30px;
			    FONT-FAMILY: 宋体;
			    BORDER-RIGHT: #FFFFFF 1px solid;
			    BORDER-TOP: #FFFFFF 1px solid;
			    BORDER-LEFT: #FFFFFF 1px solid;
			    BORDER-BOTTOM: #FFFFFF 1px solid;
			}
		</style>
		<script src="${ctx}/resources/js/jquery/jquery.js" type="text/javascript"></script>
		<script type="text/javascript">  
	var contextpath="<%=basePath%>";
		var fileSavePath=getPathBySystem(); 
		//根据操作系统用不同的路径
		function getPathBySystem(){
		     var path="";
		     var ua = navigator.userAgent.toLowerCase();
		     if(ua.indexOf("linux")>=0){
		        path="/usr/local/temp";
		     }else{
		        path="C:\\TEMP\\";
		     }
		    return path;
		}
		
		//盖章按钮
        function gzJyxkzs(){
           var chinesename = document.getElementById("sqdw").value+
           					document.getElementById("acceptNo").value+"许可证.xls";
           
           var filepath=contextpath+"/"+document.getElementById("templateFilePath").value;
  		   var filename = filepath.substring(filepath.lastIndexOf("/")+1);
  		   TransUpload(filename,chinesename,filepath)
        }
    
		function TransUpload(result,chinesename,filepath){
			var newpath=MakeWord(result,chinesename,filepath);// 打开word ，把它保存在D盘，相当于下载
			var DocName, CebName, LogName, IniName;
			var DocNameLen;
			var DocNameWONLen;
			var cebtail;
		//	DocName = NewDocForm.OriginalFile.value;
		 	DocName =newpath;
			DocNameLen = DocName.length;
			DocNameWONLen = DocName.lastIndexOf(".") - 1;
			if (DocNameWONLen == -1){
				DocNameWONLen = DocNameLen;
			}else{
				cebtail = DocName.substring(DocNameWONLen+2, DocNameLen);
			}
			if (cebtail.toLowerCase() == "ceb"){
				CebName = DocName;
			}else{
				CebName = DocName.substring(0, DocNameWONLen+1) + ".ceb";
			}
			
			LogName = DocName.substring(0, DocNameWONLen+1) + ".log";
			IniName = DocName.substring(0, DocNameWONLen+1) + ".ini";
			if (DocName != CebName){
				if (!(transMaker(DocName, CebName, LogName, IniName))){// 格式转换
					alert("格式转换失败，请重试！");
					return false;
				}		
			}
			else{
				alert("当前格式为ceb格式！");
			}
			var f=newpath.substring(0,newpath.lastIndexOf("."))+".ceb";
			Stamp_onclick(f);//盖章
			document.getElementById("t1").value=f;
			callSet(chinesename);//上传
			return true;

		}
		//格式转换
		function transMaker(DocName, CebName, LogName, IniName){
			var DTracker;
			DTracker = new ActiveXObject("MakerCom.MakerExt.1");
			var nRet;
			var Error;
			//alert("正转换文件，请稍候......");		
			nRet = DTracker.BeginMaker("");
			if (nRet != 0){
				alert(DTracker.GetErrorMessage(nRet));		
				delete DTracker;
				return false;
			}		
		    //alert("开始文档格式转换......请稍后!");		
			nRet = DTracker.SingleFileConvert(DocName, CebName, "标准模板", LogName, IniName);	
			if (nRet != 0){
				alert("MakerOcx transfer error!");
				nRet = DTracker.EndMaker();		
				delete DTracker;
				return false;
			}
			nRet = DTracker.EndMaker();
			if (nRet != 0){
				alert("MakerOcx End error!");		
				delete DTracker;
				return false;
			}	
			alert("格式转换完成！");	
			delete DTracker;
			return true;
		}
		//文件保存到本地
		 function MakeWord(filename,chinesename,filepath){
	        var WordApp=new ActiveXObject("Excel.Application");
	        var newpath=fileSavePath+chinesename;
	        var url=filepath;
        	WordApp.Visible = false;
	        var Doc=WordApp.Workbooks.open(url);
	        Doc.saveAs(newpath);
	        Doc.Close();
	        WordApp.Application.Quit();
	        return newpath;
 		}
        </script>
        <script language="vbs">
Function Stamp_onclick(strCEBFileName)    	
	Dim strErrMessage, lRet, objStampClientTool,g_AffixRegisterURL,g_SendPrintURL,UnitName
	g_AffixRegisterURL="http://172.16.253.169/StampServer/interfaces/background/AffixRegister.aspx"
	g_SendPrintURL="http://172.16.253.169/StampServer/extend/interfaces/SendPrint.aspx"
	UnitName=""

	lRet = ""
	strErrMessage = ""
	strCEBFileName = trim(strCEBFileName)

	if  0 = len(trim(strCEBFileName)) then
		Call Alert("请选择CEB文件！", vbExclamation, "请选择CEB文件！")
		Exit Function
	else
		if UCase(Right(Trim(strCEBFileName), 3)) <> "CEB" then
			Call Alert("只能选择CEB格式的文件！", vbExclamation, "只能选择CEB格式的文件！")
			CEBFileName.value = ""
			Exit Function
		end if                  	 	  
	end if

	set objStampClientTool  = CreateObject("StampClientTool.StampTool")

	' 本地可视化盖章	
	lRet = objStampClientTool.LocalSealStamp(strCEBFileName, UnitName, g_AffixRegisterURL, g_SendPrintURL)
	
	if lRet <> 0 then
		strErrMessage = objStampClientTool.GetErrorMessage()
        alert "盖章失败原因:" & strErrMessage
	end if

	Set objStampClientTool = Nothing	
End Function

Sub PreviewCEB(xuwei)
	Dim lRet
	lRet = DCreateGBForm1.ViewLocalCEB(xuwei)
End Sub

Sub PreviewNetCEB(xuwei)
	Dim lRet
	lRet = DCreateGBForm1.ViewNetCEB(xuwei)
End Sub

</script>
	</head>
	<body>
		<form name="hwggForm" id="hwggForm">
		<input type="hidden" name="id" value="${id}"/>
		<input type="hidden" name="acceptNo" id="acceptNo" value="${acceptNo}"/>
		<input type="hidden" id="activityName" value="${activityName}"/>
		<input type="hidden" id="printtype" value="${printtype}">
		<input type="hidden" name="templateFilePath" id="templateFilePath" value="${templateFilePath}">
		<table width="1024" border=0 align="center">
			<tr>
				<td class="titleCss" colspan="2">户外广告设置证</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
                <td class="justifyCss tdCss">设置证号：</td>
                <c:if test="${selectType}=='wq'"></c:if>
                <td class="inputNoborder">穗城管委${selectType}户外广设字[<%=(new java.util.Date()).getYear()+1900%>]<input name="szzh" value="${szzh}" class="inputNoborder" style="width:10%;"/>号</td>
            </tr>
			<tr>
				<td class="justifyCss tdCss">设置人名称：</td>
				<td class="tdCss"><input name="sqdw" value="${sqdw}" class="inputNoborder" style="width:100%;"/></td>
			</tr>
			<!-- 
				<tr>
					<td class="justifyCss tdCss">中标单位：</td>
					<td class="tdCss"><input name="zbdw" value="${zbdw}" class="inputNoborder" style="width:100%;"/></td>
				</tr>
			 -->
			<tr>
				<td class="justifyCss tdCss">地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址：</td>
				<s:if test="ggszd != null && ggszdlength > 18">
				    <td class="tdCss">
				        <textarea rows="2" name="ggszd" cols="" type="text" class="text" style="width:100%;font-size: 20px;">${ggszd}</textarea>
				        <!-- <input name="address" value="${address}" class="inputNoborder" style="width:100%;font-size: 20px;"/> -->
				    </td>
				</s:if>
				<s:else>
				    <td class="tdCss"><input name="ggszd" value="${ggszd}" class="inputNoborder" style="width:100%;"/></td>
				</s:else>
			</tr>
			<tr>
				<td class="justifyCss tdCss">法定代表人：</td>
                <td class="tdCss"><input name="frxm" value="${frxm}" class="inputNoborder" style="width:100%;"/></td>
			</tr> 
			<tr>
				<td class="justifyCss tdCss">设置类型：</td>
				<td class="tdCss"><input name="ggxsStr" value="${ggxsStr}" class="inputNoborder" style="width:100%;"/></td>
			</tr>
			<tr>
				<td class="justifyCss tdCss">设置规格：</td>
				<td class="tdCss"><input name="szggStr" value="${szggStr}" class="inputNoborder" size="50"/></td>
			</tr>
			<tr>
				<td class="justifyCss tdCss">设置期限：</td>
				<td class="tdCss" style="white-space: nowrap;">
				自
				<input name="startyear" value="${startyear}" class="inputNoborder" style="width:120px;"/>
                  年
                <input name="startmonth" value="${startmonth}" class="inputNoborder" style="width:45px;"/>
                  月
                <input name="startday" value="${startday}" class="inputNoborder" style="width:40px;"/>
				至
				<input name="endyear" value="${endyear}" class="inputNoborder" style="width:120px;"/>
				年
				<input name="endmonth" value="${endmonth}" class="inputNoborder" style="width:45px;"/>
				月
				<input name="endday" value="${endday}" class="inputNoborder" style="width:40px;"/>
				日</td>
			</tr>
			<tr>
				<td class="justifyCss tdCss">备 注：</td>
				<td style="FONT-SIZE: 15px;">
				    <textarea rows="2" name="bz" cols="" type="text" class="text" style="border:0;overflow-y:hidden;width:100%;font-size: 15px;height:100%">${bz}</textarea>
				</td>
			</tr>
			<tr>
				<td colspan="2"><table width="100%"><tr>
					<td width="65%"></td>
					<td style="font-size:100%;font-weight: bold;">
					发证机关：<input type="text" class="inputNoborder" name="fzjg" style="FONT-SIZE: 20px;" value="${fzjg }"/><!-- 广州市城市管理委员会 -->
					</td>
				</tr></table></td>
			</tr>
			<tr>
				<td colspan="2"><table width="100%"><tr>
					<td width="65%"></td>
					<td style="font-size:100%;font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<!--发证日期：-->
					<input name="printyear" value="${printyear }" class="inputNoborder" style="width:95px;FONT-SIZE: 20px;"/>
					年
					<input name="printmonth" value="${printmonth }" class="inputNoborder" style="width:42px;FONT-SIZE: 20px;"/>
					月
					<input name="printday" value="${printday }" class="inputNoborder" style="width:45px;FONT-SIZE: 20px;"/>
					日</td>
				</tr></table></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<!-- 
			<tr>
				<td colspan="2" style="text-align:center;font-size:150%;font-weight: bold;">广东省住房和城乡建设厅印制</td>
			</tr>
			 -->
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
				<td colspan="2" style="text-align:center;">
					<input type="button" onclick="gzJyxkzs();"  id="printzs" value="盖章" style="width:100px;"/>
					<input type="button" onclick="viewJyxkzs();"  id="printzs" value="查看盖章" style="width:100px;"/>
					<input type="button" value="关闭窗口" onclick="window.close();" style="width:100px;"/>
				</td>
			</tr>
		</table>
		</form>
		<div id="autoPrintDiv" style="display:none;"><iframe height='1000' width='700' name='autoPrintIFrame'/></div>
	</body>
</html>